{extend name='common/common' /}

{block name="style"}
<style type="text/css">
    .container-fluid .btn.btn-sm{
        float: right;
        margin-left: 10px;
    }
    .container-fluid{
        padding-right: 0px;
    }
</style>
{/block}

{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>公共客户列表</h5>
        </div>
        <div class="ibox-content">
            <!--搜索框开始 pull-right-->
            <!--   删除   -->
            <!-- <div class="container-fluid form-inline pull-right" style="margin-top: 10px">
                <button class="btn btn-danger btn-sm getIDs" data-delete="{:url('member/deleteList')}" data-param="">删除追踪客户</button>
            </div> -->
            <form id='commentForm' role="form" method="post" class="form-inline pull-left">
                <div class="content clearfix m-b">
                    <div class="form-group">
                        <label>姓名：</label>
                        <input type="text" class="form-control" id="name" name="name">
                    </div>
                    <div class="form-group">
                        <label>联系方式：</label>
                        <input type="text" class="form-control" id="phone" name="phone">
                    </div>
                    <div class="form-group">
                        <label>等级：</label>
                        <select class="form-control"  name="grade" id="grade">
                            <option value="0">请选择</option>
                            <?php foreach($gradeArr as $val):?>
                                <option value="<?=$val['id']; ?>"><?=$val['name']; ?></option>
                            <?php endforeach;?>
                        </select>
                    </div>
                    <div class="form-group">
                        <button class="btn btn-primary" type="button" style="margin-top:5px" id="search"><strong>搜 索</strong>
                        </button>
                    </div>
                </div>
            </form>
            <!--搜索框结束-->
            <div class="example-wrap">
                <div class="example-wrap">
                    <div class="example">
                        <table id="cusTable">
                            <thead>
                            <!-- <th>checkbox</th> -->
                            <th class="text-center" data-field="id">会员ID</th>
                            <th class="text-center" data-field="name">姓名</th>
                            <th class="text-center" data-field="phone">联系电话</th>
                            <th class="text-center" data-field="adress">地址</th>
                            <th class="text-center" data-field="qq">QQ</th>
                            <th class="text-center" data-field="weixin">微信</th>
                            <th class="text-center" data-field="grade">等级</th>
                            <th class="text-center" data-field="status">状态</th>
                            <th class="text-center" data-field="relation">所属咨询师</th>
                            <th class="text-center" data-field="time">加入时间</th>
                            <th class="text-center" data-field="remarks">备注</th>
                            <th class="text-center" data-field="operate">操作</th>
                            </thead>
                        </table>
                    </div>
                </div>
                <!-- End Example Pagination -->
            </div>
        </div>
    </div>
    <!-- End Panel Other -->
</div>
<!-- 获取某职位下的所有职员 -->
<div class="roleuser" style="display: none;width: 300px;padding: 30px 15px;">
    <div class="form-group">
        <label>请选择分配职员：</label>
        <select class="form-control"  name="user" id="user">
            <option value="0">请选择</option>
			<?php foreach($userK as $val): ?>
				<option value="<?=$val['id'] ;?>"><?=$val['name'] ;?></option>
			<?php endforeach;?>
        </select>
    </div>
</div>
{/block}


{block name="script"}
<script type="text/javascript">
    function initTable() {
        //先销毁表格
        $('#cusTable').bootstrapTable('destroy');
        //初始化表格,动态从服务器加载数据
        $("#cusTable").bootstrapTable({
            method: "get",  //使用get请求到服务器获取数据
            url: "{:url('member/releaseList')}", //获取数据的地址
            striped: true,  //表格显示条纹
            pagination: true, //启动分页
            pageSize: 10,  //每页显示的记录数
            pageNumber:1, //当前第几页
            pageList: [5, 10, 15, 20, 25],  //记录数可选列表
            sidePagination: "server", //表示服务端请求
            paginationFirstText: "首页",
            paginationPreText: "上一页",
            paginationNextText: "下一页",
            paginationLastText: "尾页",
            queryParamsType : "undefined",
            columns : [{
                checkbox: false,
                formatter:function(value,row,index){
                    if (row.state == true){
                        return {
                            checked : value,//设置选中
                        };
                    }
                    return value;
                },
            }],
            queryParams: function queryParams(params) {   //设置查询参数
                var param = {
                    pageNumber: params.pageNumber,
                    pageSize: params.pageSize,
                    name:$('#name').val(),
                    phone:$('#phone').val(),
                    grade:$('#grade').val(),
                    status:$('#status').val(),
                };
                return param;
            },
            onLoadSuccess: function(res){ //加载成功时执行
                if(111 == res.code){
                    window.location.reload();
                }
                layer.msg("加载成功", {time : 1000});
            },
            onLoadError: function(){  //加载失败时执行
                layer.msg("加载数据失败");
            }
        });
    }

    $(document).ready(function () {
        //调用函数，初始化表格
        initTable();

        //当点击查询按钮的时候执行
        $("#search").bind("click", initTable);

        $('.getIDs').on('click',function(){
            var checkedOn= $('#cusTable').bootstrapTable('getSelections');
            var IDs = '';
            for(var i=0;i<checkedOn.length;i++){
                if(i == 0){
                    IDs = checkedOn[0].id;
                }else{
                    IDs += ',' + checkedOn[i].id;
                }
            }
            $('.getIDs').attr('data-param',IDs);
        })
    });
	//分配至
	function distribution(id){
		layer.open({
			type: 1,
			title: '请选择分配职员',
			anim: 2,
			content: $(".roleuser"),
			btn:['确认','取消'],
			yes:function(){
				var mid = id;
				var uid = $('#user').val();
				var status = 8;
				if(uid == '' || uid == null){
					layer.msg('请选择分配职员',{time : 1000});
					return false;
				}
				$.post("{:url('member/ajaxShare')}",{
					mid:mid,
					uid:uid,
					status:status
				},function(data){
			 		if (data.code == 1) {
			 			layer.msg(data.msg,{time : 1000},function(){
							layer.closeAll();
			 				initTable();
			 			})
			 		}else {
			 			layer.msg(data.msg,{time : 1000},function(){
							layer.closeAll();
			 				return false;
			 			})
			 		}
			 	})
			},
			btn2:function(){
				layer.closeAll();
			}
		});
	}
</script>
{/block}
